package xyz.jangle.jdbc.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 *  JAVA面向对象程序设计 P344 
 *  随机查询
 * @author Administrator
 *
 */
public class JdbcRandomQuery {

	public static void main(String[] args) {

		String url = "jdbc:mysql://127.0.0.1:3306/jangle_test?characterEncoding=UTF8&serverTimezone=Asia/Shanghai";
		String user = "root";
		String password = "111111";
		try(Connection con = DriverManager.getConnection(url, user, password)){
			// 参数1.游标可上下移动，当数据库变化时，结果集不变	参数		2.能用结果集更新数据库中的表
			Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
			ResultSet resultSet = statement.executeQuery("select * from demo");
//			resultSet.next();
			resultSet.absolute(3);	// 跳到第3行
			resultSet.updateString("name", "testUpdateString");
			resultSet.updateRow();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
  
	}
}
	
